package com.bbm.communitysystem.controller.role;


import com.bbm.communitysystem.core.domain.R;
import com.bbm.communitysystem.domain.dto.role.RouterDto;
import com.bbm.communitysystem.service.IRouterService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bbm
 * @since 2025-02-13
 */
@Tag(name = "路由")
@RestController
@RequestMapping("/router")
@RequiredArgsConstructor
public class RouterController {

    private final IRouterService routerService;

    @Operation(summary = "新增路由")
    @PostMapping("/")
    public R addRouter(@RequestBody RouterDto router) {
        return routerService.addRouter(router) == 0 ? R.ok("新增成功") : R.error("新增失败");
    }

    @Operation(summary = "删除路由")
    @DeleteMapping("/{id}")
    public R delRouter(@PathVariable("id") Integer id) {
        return routerService.delRouter(id) == 0 ? R.ok("删除成功") : R.error("删除失败");
    }

    @Operation(summary = "修改路由")
    @PutMapping("/")
    public R putRouter(@RequestBody RouterDto router) {
        return routerService.putRouter(router) == 0 ? R.ok("修改成功") : R.error("修改失败");
    }

    @Operation(summary = "获取所有路由")
    @GetMapping
    public R getRouter() {
        return R.ok(routerService.list());
    }

    @Operation(summary = "获取路由")
    @GetMapping("/{id}")
    public R getRouterByUserId(@PathVariable("id") Integer userId) {
        return R.ok(routerService.getById(userId));
    }

}
